package com.chenbei.controller.admin.erp;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenbei.common.domain.vo.ApiResponse;
import com.chenbei.common.domain.vo.Pagination;
import com.chenbei.common.util.ApiResponseUtil;
import com.chenbei.erp.domain.Supplier;
import com.chenbei.erp.service.ISupplierService;
import com.chenbei.erp.vo.req.SupplierReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "供应商管理")
@RestController("AdminWMSSupplier")
@RequestMapping("/admin/erp/supplier")
public class SupplierController {

    @Autowired
    private ISupplierService supplierService;

    @Operation(summary = "新增供应商")
    @PostMapping("add")
    public ApiResponse<Boolean> add(@RequestBody Supplier supplier) {
        supplierService.add(supplier);
        return ApiResponseUtil.success(true);
    }

    @Operation(summary = "更新供应商")
    @PostMapping("update")
    public ApiResponse<Boolean> update(@RequestBody Supplier supplier) {
        supplierService.update(supplier);
        return ApiResponseUtil.success(true);
    }

    @Operation(summary = "供应商详情")
    @GetMapping("detail")
    public ApiResponse<Supplier> detail(@RequestParam Long id) {
        Supplier detail = supplierService.detail(id);
        return ApiResponseUtil.success(detail);
    }

    @Operation(summary = "供应商分页列表")
    @GetMapping("pageList")
    public ApiResponse<Pagination<Supplier>> pageList(SupplierReq supplierReq) {
        Page<Supplier> wmsSupplierPage = supplierService.pageList(supplierReq);
        return ApiResponseUtil.success(wmsSupplierPage);
    }
}
